package edu.gyc.objecthomework;/*
 * RatingScore.java
 *
 * Created on February 15, 2007, 4:09 PM
 *
 * Solution to Exercise 9
 */

/**
 *
 * @author charleshoot
 */

import java.util.Scanner;

public class RatingScore {
    
    
    
    
    private String description;
    private int maximumRating;
    private int theRating;
    
    
    
    public void initialize(String desc, int max) {
        description = desc;
        maximumRating = max;
        theRating = -1;
    }
    
    
    
    public void inputRating(){
        System.out.println("What is your rating for " + description + "?");
        System.out.println("Please enter an integer from 0 to " + maximumRating);
        
        Scanner reader = new Scanner(System.in);
        int data = -1;
        boolean needTheRating = true;
        
        while(needTheRating){
            data = reader.nextInt();
            if(data>=0 && data<=maximumRating){
                needTheRating = false;
            } else {
                System.out.println("Sorry, that rating is out of range.");
                System.out.println("Please enter an integer from 0 to " + maximumRating);
            }
        }
        
        theRating = data;
    }
    
    public int getMaxRating(){
        return maximumRating;
    }
    
    public int getRating(){
        return theRating;
    }
    
    public String getRatingString(){
        return "the rating is " + theRating + "/" + maximumRating;
    }
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        RatingScore movieRating = new RatingScore();
        RatingScore restaurantRating = new RatingScore();
        movieRating.initialize("Joe's excellent movie", 5);
        restaurantRating.initialize("Food quality", 10);
        
        movieRating.inputRating();
        System.out.println("Displaying the attributes for the movie rating.");
        System.out.println("The rating is " + movieRating.getRating() + " out of "
                + movieRating.getMaxRating());
        System.out.println();
        
        restaurantRating.inputRating();
        System.out.println("Displaying the rating for the restaurant.");
        System.out.println( restaurantRating.getRatingString());
        
        
        
        
    }
    
}

